<script>
function showReport(id)
{
	//showIndicator();
	$.ajax({'url':'<?=Yii::app()->createUrl('report/list')?>/'+id,'type':'get','success':function(data)
	{
		//hideIndicator();
		$('#report_status').html(data);
	} ,'cache':false});
	return false;
}
function showReportByStudent(id)
{
	//showIndicator();
	$.getJSON('<?=Yii::app()->createUrl('project/getActiveProject')?>/'+id,function(data)
		{
		$.ajax({'url':'<?=Yii::app()->createUrl('report/list')?>/'+data['projectID'],'type':'get','success':function(data)
			{
				//hideIndicator();
				$('#report_status').html(data);
			} ,'cache':false});
		});
	
	return false;
}
function showIndicator()
{
	var html="<ul style='text-align: center; vertical-align :top; border: none;'><li><img src='<?=Yii::app()->request->baseUrl?>/images/indicator.gif'></ul></li>";
	$('#report_status').html(html);
}

function hideIndicator()
{
	$('#report_status').html('');
}

</script>

<?php ################################?>
	<?php
		// dialog form input date for print พิมพ์หนังสือแต่งตั้งอาจารย์ที่ปรึกษา
		$this->beginWidget('zii.widgets.jui.CJuiDialog', array( // the dialog
		    'id'=>'dialogInputDateReport',
		    'options'=>array(
		        'title'=>'พิมพ์หนังสือ',
		        'autoOpen'=>false,
		        'modal'=>true,
		        'width'=>550,
		        'height'=>250,
				'buttons' => array(
						array('text'=>'ตกลง','click'=> 'js:function(){confirmPrintReport(); return false;}'),
						array('text'=>'ปิด','click'=> 'js:function(){$(this).dialog("close");}'),
				),
		    ),
		));?>
		<div class="divForInputDateReport">
			<div style="text-align: center; margin-top: 20px;">
				<form action="<?=Yii::app()->createUrl('report/print')?>" id="frmPrintReport" method="post">			
					<b id ="reportTypeCaption" style="color: blue;"></b><br><br>
					<input type="hidden" name="reportTypeId" id="reportTypeId"/>
					<input type="hidden" name="reportOfProjectId" id="reportOfProjectId"/>
					<label>วันที่ออกหนังสือ : </label>
					<?php
						$this->widget('zii.widgets.jui.CJuiDatePicker',array(
								'name'=>'txtInputDateReport',
								'id'=>'txtInputDateReport',
								'value'=>'',
								//'model'=>$model,
								//'attribute'=>'startDate',
								'language'=>'th',
								// additional javascript options for the date picker plugin
								'options'=>array(
										'mode'=>'button',
										//'dateFormat'=>'d MM, yy',
										'showOn'=>'button', // 'focus', 'button', 'both'
										'dateFormat'=>'yy-mm-dd',
										//'value'=>strftime('%d/%m/%Y', strtotime($model->docDate)),
										'showAnim'=>'fold',
										'changeMonth'=> true,
										'changeYear'=> true,
					
								),
								'htmlOptions'=>array(
										'style'=>'height:20px;',
										'readonly'=>'readonly',
								),
						));
					?> yyyy-mm-dd
				</form>
			</div>
		</div>		 
		<?php $this->endWidget();?>
		
		<?php
		// dialog form input date for print หนังสืออนุมัติโครงการ
		$this->beginWidget('zii.widgets.jui.CJuiDialog', array( // the dialog
		    'id'=>'dialogUploadReport',
		    'options'=>array(
		        'title'=>'นำเข้าไฟล์หนังสือประเภทต่างๆ',
		        'autoOpen'=>false,
		        'modal'=>true,
		        'width'=>550,
		        'height'=>250,
				'buttons' => array(
						array('text'=>'ตกลง','click'=> 'js:function(){$(\'#formUploadReport\').submit();$(this).dialog("close");}'),
						array('text'=>'ปิด','click'=> 'js:function(){$(this).dialog("close");}'),
				),
		    ),
		));?>
		<div class="divForUploadReport">
			<div style="text-align:center; margin-top: 20px;">
				<form action="<?=Yii::app()->createUrl('report/upload')?>" method="post" enctype='multipart/form-data' id="formUploadReport" target="fileuploads">					
					<b id ="fileReportCaption" style="color: blue;"></b>
					<input type="hidden" name="fileDocumentName" id="fileDocumentName"/>
					<input type="hidden" name="fileDocumentID" id="fileDocumentID"/>
					<input type="hidden" name="fileProjectID" id="fileProjectID"/>
					<input type="hidden" name="fileReportTypeID" id="fileReportTypeID"/>
					<input type="file" name="fileReportUpload" id="fileReportUpload"/>
				</form>
			</div>
		</div>
		<iframe name="fileuploads" frameborder="0" height="0" width="0"></iframe>
		<?php $this->endWidget();?>
		
		<script type="text/javascript">
			//function printReport(){
			function printReport(reportTypeId,reportname,projectId)
			{
				$("#txtInputDateReport").val("");
				$("#reportTypeCaption").html(reportname);
				$("#reportTypeId").val(reportTypeId);
				$("#reportOfProjectId").val(projectId);
				$("#dialogInputDateReport").dialog("open");
			}

			function confirmPrintReport()
			{
				var reportTypeId = $("#reportTypeId").val();
				var projectID = $("#reportOfProjectId").val();
				var reportDate= $("#txtInputDateReport").val();
				//alert("Date : " + reportDate);
				//alert("projectID="+projectID+",reportTypeID="+reportTypeId+",reportDate="+reportDate);
				if(reportDate.length < 1){
					alert("Please select report date.");
				}
				else{
					//$("#frmPrintReport").submit();
					
					var url="<?=Yii::app()->createUrl('report/print')?>?projectID="+projectID+"&reportTypeID="+reportTypeId+"&reportDate="+reportDate;
					window.open(url, '_blank');
					$("#dialogInputDateReport").dialog("close");
					
				}
			}
			
			function delReport(reporttype,reportname,docid,projectID){
				if(confirm('คุณต้องการลบไฟล์ : ' + reportname + ' จริง ใช่หรือไม่ ?.') == true){
					//var docid=$("#hiddenDelReport"+reporttype).val();
					//alert('Yes confirm.' + docid);
					$.ajax({'url':'<?=Yii::app()->createUrl('report/delete')?>/'+docid,'type':'get','success':function(data)
			            {
			          		alert('Delete complete.');
			          		//window.location.reload(true);
			          		showReport(projectID);
			            } ,'cache':false});
				}
				else{
					//alert('No confirm.');
					return false;
				}
				return false;
			}

			function reloadReport(id)
			{
				showIndicator();
				$.ajax({'url':'<?=Yii::app()->createUrl('report/list')?>/'+id,'type':'get','success':function(data)
				{
					hideIndicator();
					$('#report_status').html(data);
				} ,'cache':false});
				return false;
			}

			function openReport(documentID){
				//alert("DocumentID : " + documentID);
				var url="<?=Yii::app()->createUrl('report/view')?>/"+documentID;
				window.open(url, '_blank');
			}
			
			function uploadReport(reportname,docid,projectID,reportTypeID){
				//alert("reportname ="+reportname+",docid=" + docid + ",projectID="+projectID+",reportTypeID="+reportTypeID);
				$("#fileReportUpload").val("");
				$("#fileReportCaption").html("ไฟล์"+reportname);
				$("#fileDocumentID").val(docid);
				$("#fileDocumentName").val(reportname);
				$("#fileProjectID").val(projectID);
				$("#fileReportTypeID").val(reportTypeID);
				$("#dialogUploadReport").dialog("open");
			}
		</script>